#include "usbconnwin.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFont>

UsbConnWin::UsbConnWin(QWidget *parent) : QWidget(parent)
{
    m_connDescLab = new QLabel(this);
    m_choiceDescLab = new QLabel(this);
    m_modelBox = new QComboBox(this);
    m_imageChart = new RotationChart(this);

    QFont font;
    font.setBold(true);
    m_connDescLab->setFont(font);

    m_connDescLab->setText(tr("Complete the connection tutorial"));
    m_choiceDescLab->setText(tr("Mobile phone model"));

    QStringList modelist;
    modelist << m_vvStr << m_hwStr << m_xmStr << m_oppoStr << m_sxStr << m_otherStr;
    m_modelBox->addItems(modelist);

    connect(m_modelBox, &QComboBox::currentTextChanged, this, &UsbConnWin::valueChanged);

    m_nowFlag = m_vvStr;

    QHBoxLayout *hLayout2 = new QHBoxLayout();
    hLayout2->addStretch();
    hLayout2->addWidget(m_connDescLab);
    hLayout2->addSpacing(10);
    hLayout2->addWidget(m_choiceDescLab);
    hLayout2->addWidget(m_modelBox);
    hLayout2->addStretch();

    QHBoxLayout *hLayout3 = new QHBoxLayout;
    hLayout3->addStretch();
    hLayout3->addWidget(m_imageChart);
    hLayout3->addStretch();

    QVBoxLayout *vLayout = new QVBoxLayout();
    vLayout->addLayout(hLayout2);
    vLayout->addLayout(hLayout3);

    setLayout(vLayout);
}

UsbConnWin::~UsbConnWin() {}

void UsbConnWin::setLightUI()
{
    m_imageChart->setLightUI();
    m_vvImageList.clear();
    m_hwImageList.clear();
    m_xmImageList.clear();
    m_oppoImageList.clear();
    m_sxImageList.clear();
    m_otherImageList.clear();
    QString locale = QLocale::system().name();
    if (locale == "zh_CN") {
        locale = "zh";
    } else {
        locale = "en";
    }
    m_vvImageList << ":/icon/vivo/light" + locale + "1.png"
                  << ":/icon/vivo/light" + locale + "2.png";
    m_hwImageList << ":/icon/hw/light" + locale + "1.png"
                  << ":/icon/hw/light" + locale + "2.png";
    m_xmImageList << ":/icon/xm/light" + locale + "1.png"
                  << ":/icon/xm/light" + locale + "2.png";
    m_oppoImageList << ":/icon/oppo/light" + locale + "1.png"
                    << ":/icon/oppo/light" + locale + "2.png";
    valueChanged(m_nowFlag);
}

void UsbConnWin::setDarkUI()
{
    m_imageChart->setDarkUI();
    m_vvImageList.clear();
    m_hwImageList.clear();
    m_xmImageList.clear();
    m_oppoImageList.clear();
    m_sxImageList.clear();
    m_otherImageList.clear();
    QString locale = QLocale::system().name();
    if (locale == "zh_CN") {
        locale = "zh";
    } else {
        locale = "en";
    }
    m_vvImageList << ":/icon/vivo/dark" + locale + "1.png"
                  << ":/icon/vivo/dark" + locale + "2.png";
    m_hwImageList << ":/icon/hw/dark" + locale + "1.png"
                  << ":/icon/hw/dark" + locale + "2.png";
    m_xmImageList << ":/icon/xm/dark" + locale + "1.png"
                  << ":/icon/xm/dark" + locale + "2.png";
    m_oppoImageList << ":/icon/oppo/dark" + locale + "1.png"
                    << ":/icon/oppo/dark" + locale + "2.png";
    valueChanged(m_nowFlag);
}

void UsbConnWin::valueChanged(QString text)
{
    m_imageChart->clearImageList();
    if (m_vvStr == text) {
        m_imageChart->setImageList(m_vvImageList);
    } else if (m_hwStr == text) {
        m_imageChart->setImageList(m_hwImageList);
    } else if (m_xmStr == text) {
        m_imageChart->setImageList(m_xmImageList);
    } else if (m_oppoStr == text) {
        m_imageChart->setImageList(m_oppoImageList);
    } else if (m_sxStr == text) {
        m_imageChart->setImageList(m_sxImageList);
    } else if (m_otherStr == text) {
        m_imageChart->setImageList(m_otherImageList);
    }
}
